package com.leolian.spring02.activemq;
import javax.jms.TextMessage;  
  


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;  
import org.springframework.stereotype.Component;
  
/**
 * @author Administrator
 * @description 消费者 
 */
@Component
public class SpringConsumer {  
	
	@Autowired
    private JmsTemplate jmsTemplate;  
	
    //接收消息  
    public void recive() {  
        while (true) {  
            try {  
                //使用JMSTemplate接收消息  
                TextMessage txtmsg = (TextMessage) jmsTemplate.receive();  
                if (null != txtmsg) {  
                    System.out.println("--- 收到消息内容为: " + txtmsg.getText());  
                } else {  
                    break;  
                }  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
  
        }  
    }  
  
}  